package com.nbjtjc.safe.api.emg.handle;

import com.nbjtjc.safe.api.AbstractController;
import com.nbjtjc.safe.bean.Page;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.model.emg.handle.EmgHandle;
import com.nbjtjc.safe.service.emg.handle.EmgHandleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin("*")
@RequestMapping("/emgHandle")
@Api("应急处置的模板")
public class EmgHandleController  {

    @Autowired
    private EmgHandleService emgHandleService;

    @RequestMapping(value = "/add",method = {RequestMethod.POST})
    public Result add(@RequestBody EmgHandle emgHandle){
        Result result=new Result();
        try {
            result=emgHandleService.add(emgHandle);
        } catch (Exception e) {
            e.printStackTrace();
            result.setFalse(e.getMessage());
        }
        return result;
    }
    @RequestMapping(value = "/update",method = {RequestMethod.POST})
    public Result update(@RequestBody EmgHandle emgHandle){
        Result result=new Result();
        try {
            result=emgHandleService.update(emgHandle);
        } catch (Exception e) {
            e.printStackTrace();
            result.setFalse(e.getMessage());
        }
        return result;
    }

    @RequestMapping(value = "/delete",method = {RequestMethod.POST})
    public Result delete(@RequestBody EmgHandle emgHandle) {
        Result result=new Result();
        try {
            result=emgHandleService.delete(emgHandle.getId());
        } catch (Exception e) {
            e.printStackTrace();
            result.setFalse(e.getMessage());
        }
        return result;
    }

    @RequestMapping(value = "/find",method = {RequestMethod.POST,RequestMethod.GET})
    public Result find(@RequestBody EmgHandle emgHandle) {

        Result result=new Result();
        try {
            result=emgHandleService.find(emgHandle);
        } catch (Exception e) {
            e.printStackTrace();
            result.setFalse(e.getMessage());
        }
        return result;
    }
}
